package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zhentao.common.enums.admin.AdMembership;
import com.zhentao.dtos.Result;
import com.zhentao.mapper.AdMembershipMapper;
import com.zhentao.service.AdMembershipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author 小明
* @description 针对表【ad_membership(会员表)】的数据库操作Service实现
* @createDate 2024-09-09 10:27:20
*/
@Service
public class AdMembershipServiceImpl extends ServiceImpl<AdMembershipMapper, AdMembership>
    implements AdMembershipService{

    @Autowired
    private AdMembershipMapper adMembershipMapper;

    @Override
    public Result membershipList() {
//        LambdaQueryWrapper<AdMembership> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(AdMembership::getIsDeleted, 1);
        List<AdMembership> adMemberships = adMembershipMapper.selectList(null);
        return Result.success("操作成功").put("data", adMemberships);
    }

    @Override
    
    public Result membershipAdd(AdMembership adMembership) {


        if (adMembership.getId() == null){
            adMembership.setCreatedTime(new Date());
            adMembership.setStatus(0);
        }else {
            adMembership.setUpdatedTime(new Date());
        }
        boolean b = this.saveOrUpdate(adMembership);
        if (b){
            return Result.success("操作成功");
        }else {
            return Result.error("操作失败");
        }
//        int insert = adMembershipMapper.insert(adMembership);
//        if (insert == 0) {
//            return Result.error("添加失败");
//        }else {
//            return Result.success("添加成功");
//        }
    }

    @Override
    public Result membershipUpdate(AdMembership adMembership) {

        adMembership.setUpdatedTime(new Date());
        int update = adMembershipMapper.updateById(adMembership);
        if (update == 0) {
            return Result.error("操作失败");
        }else {
            return Result.success("操作成功");
        }
    }

    @Override
    public Result membershipDelete(Integer id) {

        int delete = adMembershipMapper.deleteById(id);
        if (delete == 0) {
            return Result.error("操作失败");
        }else {
            return Result.success("操作成功");
        }
    }
}




